package com.xiaohe66.web.domain.im.agg;

import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.im.value.ImUserId;
import com.xiaohe66.web.domain.im.value.ImUserNickname;
import com.xiaohe66.web.domain.im.value.ImUserPublicKey;
import com.xiaohe66.web.domain.im.value.ImUserSignature;
import com.xiaohe66.web.integration.domain.Aggregate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

import java.util.Objects;

/**
 * @author xiaohe
 * @since 2023-09-07 16:22
 */
@Builder
@Getter
@ToString
@AllArgsConstructor
public class ImUser implements Aggregate<ImUser, ImUserId> {

    @NonNull
    private final ImUserId id;

    @NonNull
    private final AccountId createId;

    private ImUserNickname nickname;

    private ImUserSignature signature;

    private ImUserPublicKey publicKey;

    public void changePublicKey(ImUserPublicKey publicKey) {
        this.publicKey = publicKey;
    }

    @Override
    public boolean hasSameRootAttribute(ImUser other) {
        return other != null
                && Objects.equals(nickname, other.nickname)
                && Objects.equals(signature, other.signature)
                && Objects.equals(publicKey, other.publicKey);
    }
}
